home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
kgb104.zip
/
KGB.ASM
< prev
next >
Wrap
Assembly Source File
|
1992-04-16
|
13KB
|
633 lines
.8086
.model small
.stack 200h
.code
ResBeg label byte
BuffPos dw 0
BuffSize dw 100h
Old21 dd ?
status dd ?
Off db 0
path db 'C:\HISTORY.DAT',0
db 112 dup (0)
functions db 3ch,3dh,41h,4bh,5bh
IFDEF FIND
db 4eh
ENDIF
NFunc equ $ - functions
OK db ?
func_table dw CreateFil ;3ch - create handle
dw OpenFil ;3dh - open handle
dw DeleteFil ;41h - delete file
dw Exec ;4bh - load & execute
dw CreateNew ;5bh - create New File
IFDEF FIND
dw FindFile ;4eh - find file
ENDIF
MyPSP dw ?
;----------------- Program ---------------------
IntHandler proc far
cmp cs:[Off],1
je Done
push ax
push bx
push cx
push dx
push si
push di
push es
push ds
push bp
mov bp,sp
ParDs equ ss: word ptr [bp+ 2]
ParEs equ ss: word ptr [bp+ 4]
ParDx equ ss: word ptr [bp+10]
ParCx equ ss: word ptr [bp+12]
ParBx equ ss: word ptr [bp+14]
ParAx equ ss: word ptr [bp+16]
ParFlg equ ss: word ptr [bp+22]
cmp ax,0c6c6h
jne PolCont
mov ax,ParFlg
or ax,1
mov ParFlg,ax
mov ax,cs
add sp,18
iret
PolCont: mov ax,cs
mov ds,ax
mov ax,ParAx
mov si,0
next: cmp si,NFunc
je cont
cmp ah,functions[si]
je subr
inc si
jmp next
Subr: shl si,1
call func_table[si]
cont: mov sp,bp
pop bp
pop ds
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
Done: jmp cs:[Old21]
;----------------------------------------------------------
IntHandler ENDP
;---------------------------------------------------------
CreateFil: call cont1
db 'CreateFile : ',0
CreateNew: call Cont1
db 'CreateNew : ',0
DeleteFil: call cont1
db 'DeleteFile : ',0
IFDEF FIND
FindFile: call cont1
db 'FindFile : ',0
ENDIF
;---------------------------------------------------------
OpenFil: mov ax,ParAX
cmp al,0
jne OpenFil1
call cont1
db 'OpenFile-R : ',0
OpenFil1: cmp al,1
jnz OpenFil2
call cont1
db 'OpenFile-W : ',0
OpenFil2: call cont1
db 'OpenFile-R/W: ',0
;---------------------------------------------------------
Exec: call Exec1
db 'Exec : ',0
Exec1: pop si
ExLop: lodsb
or al,al
jz ExCont
call PutBuff
jmp ExLop
ExCont: call PutStr
mov al,' '
call PutBuff
call PutParStr
call PutCrLf
call ApendTMP
retn
;---------------------------------------------------------
Cont1: pop si
CoLop: lodsb
or al,al
jz CoCont
call PutBuff
jmp CoLop
CoCont: call PutStr
call PutCrLf
call ApendTMP
retn
;---------------------------------------------------------
PutParStr: mov es,parES
mov bx,parBX
inc bx
inc bx
mov si,es:[bx]
inc bx
inc bx
mov ax,es:[bx]
mov ds,ax
lodsb
cmp al,0
jz ParEnd
xor ah,ah
mov cx,ax
Par1: lodsb
cmp al,0
jz ParEnd
cmp al,0dh
jz ParEnd
call PutBuff
loop Par1
ParEnd: retn
;---------------------------------------------------------
PutStr: mov ds,parDS
mov si,parDX
put1: lodsb
cmp al,0
jz StrEnd
call PutBuff
jmp Put1
StrEnd: retn
;---------------------------------------------------------
PutCrLf: mov al,0dh
call PutBuff
mov al,0ah
call PutBuff
retn
;---------------------------------------------------------
putbuff proc near
mov bx,cs:[BuffPos]
inc bx
cmp bx,cs:[BuffSize]
je rret
mov cs:[BuffPos],bx
add bx,offset ResEnd
dec bx
mov cs:[bx],al
rret: retn
putbuff endp
;-----------------------------------------------------------
ApendTMP proc near
call SetCrit
call DosOK
jnz stop
Call OpenFile
JNB handleOk
call CreateFile
Call OpenFile
jc stop
handleOk: MOV BX,AX ;store file handle
MOV AL,02h ;eof move
MOV CX,0 ;file offset
MOV DX,0 ;lo(offset)
MOV AH,42h ;set file pointer
pushf
call cs:[Old21]
WriteTMP: MOV DX,offset ResEnd
mov ax,cs
mov ds,ax
mov cx,buffpos ;number of bytes
MOV AH,40h ;write to the file
pushf
call cs:[Old21]
MOV AH,3Eh ;close file
pushf
call cs:[Old21]
mov buffpos,0
stop: call RestoreCrit
retn
ApendTMP ENDP
;-----------------------------------------------------------
OpenFile proc near
PUSH CS
POP DS
MOV DX,offset path
MOV AL,1 ;writing
MOV AH,3Dh ;open file handle
pushf
call cs:[Old21]
ret
OpenFile endp
;----------------------------------------------------------
CreateFile proc near
call DosOK
jz CreateCnt
stc
ret
CreateCnt: push cs
pop ds
MOV DX,offset path
MOV CX,0 ;file attribute
MOV AH,5bh ;create new file
pushf
call cs:[Old21]
jnb CreateCnt1
stc
ret
CreateCnt1: MOV BX,AX ;store file handle
MOV AH,3Eh ;close file handle
pushf
call cs:[Old21]
clc
ret
CreateFile endp
;-----------------------------------------------------------
DosOK proc near
PUSH BX
PUSH ES
LES BX,cs:[status]
CMP BYTE PTR es:[BX],0
POP ES
POP BX
RETN
DosOK ENDP
;----------------------------------------------------------
SetCrit proc near
pushf
push ax
push dx
push es
cli
mov ax,0
mov es,ax
mov ax,Word Ptr es:[24h*4]
mov Word Ptr cs:[Old24],ax
mov ax,Word Ptr es:[24h*4+2]
mov Word Ptr cs:[offset Old24 + 2],ax
mov ax,cs
mov Word Ptr es:[24h*4+2],ax
mov ax,offset New24
mov Word Ptr es:[24h*4],ax
mov ax,3300h
pushf
call cs:Old21 ;get ctrl-break state
mov cs:[CtrlC],dl
sub dl,dl
mov al,1
pushf
call cs:Old21 ;set ctrl-break off
pop es
pop dx
pop ax
popf
ret
SetCrit endp
;----------------------------------------------------------
RestoreCrit proc near
pushf
push ax
push dx
push es
cli
mov ax,0
mov es,ax
mov ax,Word Ptr cs:[Old24]
mov Word Ptr es:[24h*4],ax
mov ax,Word Ptr cs:[offset Old24 + 2]
mov Word Ptr es:[24h*4+2],ax
mov ax,3301h
mov dl,cs:[CtrlC]
pushf
call cs:[Old21]
pop es
pop dx
pop ax
popf
ret
RestoreCrit endp
;----------------------------------------------------------
Old24 dd ?
CtrlC db ?
;----------------------------------------------------------
New24 proc far ;critical err.
mov al,3 ;fail
mov Byte Ptr CS:[Off],1
iret
;----------------------------------------------------------
New24 endp
;----------------------------------------------------------
ResEnd label byte
;----------------------------------------------------------
prompt db 'Runtime saving of file actions.',13,10
db 'ver. 1.04',13,10
db 'Petr Horák, Praha 1992',13,10
db 'Usage: kgb [file] [/Options] ..',13,10
db 'Options:',0dh,0ah
db ' /u unload',0dh,0ah
db ' /dX drive X (A-Z)',0dh,0ah
db ' /on (off)',0dh,0ah,'$'
;----------------------------------------------------------
UnloadReq db 0
Default db 1
;----------------------------------------------------------
ReadCmdLine: mov ax,6200h
int 21h ;get PSP address
mov ds,bx
MOV si,81h
MOV cl,Byte Ptr ds:[80h]
xor ch,ch
ReadLoop: call SkipSpace
cmp al,'/'
jnz ReadCont
call Switch
jmp ReadLoop
ReadCont: cmp Byte Ptr cs:[Default],0
je ReadLoop ;name
push cx
dec si
call NameSet
inc si
pop cx
jmp ReadLoop
;----------------------------------------------------------
SkipSpace: cmp cx,0
jz CmdEnd
dec cx
lodsb ;al <- ds:[si]
cmp al,'/'
jz SkipEnd
cmp al,0dh
jz CmdEnd
cmp al,0
jz CmdEnd
cmp al,' '
jnz SkipSpace
SkipSpace1: cmp cx,0
jz CmdEnd
dec cx
lodsb ;al <- ds:[si]
cmp al,0dh
jz CmdEnd
cmp al,0
jz CmdEnd
cmp al,' '
jz SkipSpace1
SkipEnd: ret
;----------------------------------------------------------
CmdEnd: pop ax
ret
;----------------------------------------------------------
Switch: cmp cx,0
jz CmdEnd
lodsb
dec cx
cmp al,'u'
jnz Read4
mov cs:[UnloadReq],1
jmp CmdEnd
Read4: cmp al,'d'
jnz Read5
cmp cs:[Default],0
jz Read5
cal